﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Save_Click(object sender, EventArgs e)
    {
        CmsDataContext db = new CmsDataContext();

        try
        {
            Manager manager = (from aM in db.Manager
                               where aM.ID == Toolkit.CurrentUserID
                               select aM).First();

            if (Toolkit.EncryptPassword( OldPassword.Text.Trim()) != manager.Password)
            //if (OldPassword.Text.Trim() != manager.Password)
            {
                MessageBox.Message = "旧密码输入错误，请重新输入。";
                MessageBox.Location = "./ChangePassword.aspx";
                return;
            }
            else
            {
                manager.Password = Toolkit.EncryptPassword(NewPassword.Text.Trim());

                db.SubmitChanges();

                MessageBox.Message = "密码修改成功，下次登录请使用新密码。";
                MessageBox.Location = "./Default.aspx";
            }
        }
        catch(Exception ee)
        {
            MessageBox.Message = "修改密码时发生错误："+ee.Message;
            MessageBox.Location = "./Default.aspx";
        }
    }
}